﻿/*
* Copyright (c) 2010-2012 Tesla Engine Group
* 
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
* 
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
* 
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/


using System;

namespace Tesla.Core {
    /// <summary>
    /// GameTime is a snapshot of time during the simulation. It is managed by the GameTimer class for
    /// its values to be set.
    /// </summary>
    public sealed class GameTime {
        private TimeSpan _elapsedGameTime;
        private TimeSpan _totalGameTime;
        private double _tpf;

        /// <summary>
        /// Elapsed time since the last snapshot.
        /// </summary>
        public TimeSpan ElapsedGameTime {
            get {
                return _elapsedGameTime;
            }
            internal set {
                _elapsedGameTime = value;
            }
        }

        /// <summary>
        /// Total time the simulation has been running.
        /// </summary>
        public TimeSpan TotalGameTime {
            get {
                return _totalGameTime;
            }
            internal set {
                _totalGameTime = value;
            }
        }

        /// <summary>
        /// Convience method for getting the elapsed time since the last snapshot
        /// in seconds. Alternatively you can use GameTime.ElapsedGameTime.TotalSeconds,
        /// although this value is cached.
        /// </summary>
        public double ElapsedTimeInSeconds {
            get {
                return _tpf;
            }
            internal set {
                _tpf = value;
            }
        }

        /// <summary>
        /// Creates a new GameTime snapshot with the specified elapsed time and total time.
        /// </summary>
        /// <param name="elapsedGameTime">Elapsed time</param>
        /// <param name="totalGameTime">Total time</param>
        public GameTime(TimeSpan elapsedGameTime, TimeSpan totalGameTime) {
            _elapsedGameTime = elapsedGameTime;
            _totalGameTime = totalGameTime;
            _tpf = elapsedGameTime.TotalSeconds;
        }
    }
}
